<template>
  <div class="login-page">
    <el-form
      :model="ruleForm"
      ref="ruleForm"
      label-width="10px"
      class="demo-ruleForm"
      :rules="rules"
    >
      <img src="@/assets/likedelogo.png" alt="" class="logo" />
      <el-form-item prop="loginName">
        <el-input
          placeholder="请输入用户名"
          v-model="ruleForm.loginName"
          autocomplete="off"
          prefix-icon="el-icon-mobile-phone"
        ></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input
          placeholder="请输入密码"
          type="password"
          v-model="ruleForm.password"
          autocomplete="off"
          prefix-icon="el-icon-lock"
          show-password
        ></el-input>
      </el-form-item>
      <el-form-item prop="code">
        <el-input
          type="text"
          v-model="ruleForm.code"
          autocomplete="off"
          prefix-icon="el-icon-message"
          placeholder="请输入验证码"
          ><i slot="suffix">
            <img
              class="img"
              :src="
                'http://localhost:8080/likede/api/user-service/user/imageCode/' +
                randCode
              "
              alt=""
              @click="changeCode" /></i
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="medium" type="primary" @click="submitForm"
          >登录</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'LikedeLogin',

  data () {
    return {
      ruleForm: {
        loginName: 'demo',
        password: '888itcast.CN764%...',
        code: ''
      },
      randCode: 666,
      rules: {
        loginName: [{ required: true, message: '用户名必填', trigger: 'blur' }],
        password: [{ required: true, message: '密码必填', trigger: 'blur' }],
        code: [{ required: true, message: '验证码必填', trigger: 'blur' }]
      }
    }
  },

  methods: {
    creatCode () {
      this.randCode = Math.random()
    },
    async submitForm () {
      await this.$refs.ruleForm.validate()
      this.$store.dispatch('user/loginAction', {
        ...this.ruleForm,
        loginType: 0,
        clientToken: this.randCode
      })
    },
    changeCode () {
      this.creatCode()
    }
  }
}
</script>

<style lang="scss" scoped>
.login-page {
  min-height: 100vh;
  background: url(@/assets/bgc.png) no-repeat center / cover;
  // flex 实现水平垂直居中
  display: flex;
  align-items: center;
  justify-content: space-around;
  .el-form {
    position: absolute;
    width: 400px;
    height: 300px;
    top: 50%;
    left: 50%;
    margin-top: -225px;
    margin-left: -259px;
    padding: 76px 35px 0;
    background: #fff;
    -webkit-box-shadow: 0 3px 70px 0 rgba(30, 111, 72, 0.35);
    box-shadow: 0 3px 70px 0 rgba(30, 111, 72, 0.35);
    border-radius: 10px;
  }
  .logo {
    position: absolute;
    width: 96px;
    height: 96px;
    top: -46px;
    left: 50%;
    margin-left: -48px;
  }
  .el-button {
    width: 100%;
    height: 52px;
    background: linear-gradient(262deg, #2e50e1, #6878f0);
    opacity: 0.91;
    border-radius: 8px;
    color: #fff;
    text-shadow: 0 7px 22px #cfcfcf;
  }
  .img {
    position: absolute;
    width: 130px;
    height: 40px;
    right: -5px;
  }
}
</style>
